<?php
namespace Api\Application;

use Api\Application;
use Api\Http\Request;
use Api\Http\Response;

/**
 * Class Error
 * @package Api\Application
 * @author Steffen Brem <steffenbrem@gmail.com>
 */
class Error
{
    /**
     * @var \Api\Application
     */
    protected $application;

    /**
     * @var Request
     */
    protected $request;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->application = Application::$shared;
    }

    /**
     * @param \Exception $e
     */
    public function displayException(\Exception $e)
    {
        ob_end_clean();

        if ($this->application->config['application']['debug'] == true)
        {
            header("Content-Type: text/html");
            include "error/exception.phtml";
        }
        else
        {
            $response['error'] = array(
                'type' => get_class($e),
                'code'      => $e->getCode(),
                'message'   => $e->getMessage(),
                'file'      => $e->getFile(),
                'line'      => $e->getLine()
            );

            $r = new Response(Response::BAD_REQUEST, $response);
            $r->output();
            die("No debug mode not yet implemented!");
        }
    }
}